// ==================================================================
// 描 述：
// 作 者：王征:D
// 创建时间：2019/05/20 14:16:45
// ==============================================================
using ProtoBuf.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace AutoChess
{
    public class AutoChessRewardCell : MonoBehaviour
    {
        public GameObject CurrentMark;
        public CommonIcon CommonItem;
        public Transform Content;

        public GroupSpriteKit GroupSprite;

        private Table.DataModel.TableAutoChessGrade _tableGrade;
        //private List<ItemBase> _weekRewards;
        private List<ItemBase> _seasonRewards = new List<ItemBase>();

        public void SetData(List<Table.DataModel.TableAutoChessGrade> grades)
        {
            _tableGrade = grades[0];
            var curTableGrade = Table.Blo.AutoChessBlo.GetGradeById(AutoChessManager.Ins.cacheData.Grade);
            CurrentMark.SetActive(curTableGrade.rankType == _tableGrade.rankType);
            //_weekRewards = CommonMethod.ParseItemBase(tableGrade.weekReward);
            foreach (var item in grades)
            {
                var rewards = CommonMethod.ParseItemBase(item.seasonReward);
                _seasonRewards.AddRange(rewards);
            }
            GroupSprite.SetSpriteName(_tableGrade.gradeIconSmall);
        }

        public void SetDisplayType(int type)
        {
            // type == 0: 每周奖励
            List<ItemBase> displayItems = type == 0 ? _seasonRewards : _seasonRewards;
            Content.DestroyChildren();
            for (int i = 0; i < _seasonRewards.Count; i++)
            {
                var item = _seasonRewards[i];
                var commonItem = Instantiate<CommonIcon>(CommonItem, Content);
                commonItem.gameObject.SetActive(true);
                commonItem.SetData(item.id, item.type, item.num);
            }
        }
    }
}
